package dang.action.cart;

import java.io.UnsupportedEncodingException;
import java.util.Iterator;
import java.util.List;

import dang.action.DangAction;
import dang.common.CookieUtil;

public class RecoveryItemAction extends DangAction{
	private int id;
	
	public String execute() throws UnsupportedEncodingException {
		String cartInfoId=(String) session.get("cartInfoId").toString();
		Cart cart = (Cart) session.get("cart");
		List<CartItem>items=cart.list();
		for (Iterator<CartItem> iter = items.iterator(); iter.hasNext();) {
			CartItem item = (CartItem) iter.next();
			if(item.getProduct().getId()==id){
				item.getProduct().setDeleted(false);
				CookieUtil.saveCookie("cartInfo"+cartInfoId, cart.store(), response);
				break;
			}
		}
		return "success";
	}
	

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
}
